//
//  ResumeViewController.m
//  InviteJob
//
//  Created by LangLang on 17/10/27.
//  Copyright © 2017年 Shui. All rights reserved.
//

#import "ResumeViewController.h"
#import "ResumeModel.h"
#import "JobsChooseViewController.h"
#import "AddCertificateViewController.h"//专业证书
#import "CertificateModel.h"//专业证书model

#import "AddEducationViewController.h"//教育经验
#import "EducationModel.h"//教育经验model

#import "AddWorkExperienceViewController.h"//工作经验
#import "WorkExperienceModel.h"//工作经验model

#import "AddProjectExperienceViewController.h"//项目经验
#import "ProjectExperienceModel.h"//项目经验model

static NSString *strCell = @"strCell";

@interface ResumeViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIPickerViewDataSource, UIPickerViewDelegate,UITextViewDelegate>
 
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UITextField *textField;
@property (nonatomic,strong) ResumeModel *model;//基本信息
@property(nonatomic, strong) NSMutableArray *dataCertificateModelArray;//专业证书array
@property(nonatomic, strong) NSMutableArray *dataEducationModelArray;//教育经验array
@property(nonatomic, strong) NSMutableArray *dataWorkExperienceModelArray;//工作经验array
@property(nonatomic, strong) NSMutableArray *dataProjectExperienceModelArray;//项目经验array
@property(nonatomic, strong) SZTextView *textAssessment;//自我评价

// 添加需要传入json类型
@property(nonatomic, strong) NSString *strJsonCertificate;
@property(nonatomic, strong) NSString *strJsonEducation;
@property(nonatomic, strong) NSString *strJsonWorkExperience;
@property(nonatomic, strong) NSString *strJsonProjectExperience;

@end

@implementation ResumeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = strColor(@"f6f6f6");
    TitleView(@"简历详情")
    
    self.mem_province = @"";
    self.mem_city = @"";
    self.mem_country = @"";
    
    _model.strJobAddress = @"北京北京市东城区";
    
    if (_strResumeId) {
       [self getListDatas];
    }
    
    [self layoutUI];
    
    _model = [ResumeModel new];
    // 岗位
    //注册通知(等待接收消息)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(volue:) name:@"volue" object:nil];
    
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark  保存按钮
- (IBAction)btnSaveUpdata:(id)sender {
    
    [self upPostData];
    
}



-(NSMutableArray *)dataCertificateModelArray{
    if (!_dataCertificateModelArray) {
        _dataCertificateModelArray = @[].mutableCopy;
    }
    return _dataCertificateModelArray;
}
-(NSMutableArray *)dataEducationModelArray{
    if (!_dataEducationModelArray) {
        _dataEducationModelArray = @[].mutableCopy;
    }
    return _dataEducationModelArray;
}
-(NSMutableArray *)dataWorkExperienceModelArray{
    if (!_dataWorkExperienceModelArray) {
        _dataWorkExperienceModelArray = @[].mutableCopy;
    }
    return _dataWorkExperienceModelArray;
}
-(NSMutableArray *)dataProjectExperienceModelArray{
    if (!_dataProjectExperienceModelArray) {
        _dataProjectExperienceModelArray = @[].mutableCopy;
    }
    return _dataProjectExperienceModelArray;
}
#pragma mark -- 获得岗位参数
-(void)volue:(NSNotification *)sender{
    
    _model.strJobs = sender.userInfo[@"cate_name"];
    _model.strCateId = sender.userInfo[@"cate_id"];
    [self reloadInputViewsRow:0 andSection:0];
    
}

-(void)layoutUI{
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 0, WIDTH-20, HEIGHT-64-70) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.separatorStyle = UITableViewCellAccessoryNone;
    _tableView.backgroundColor = strColor(@"f6f6f6");
    [self.view addSubview:_tableView];
    
    
    // picker
    self.pickerView = [[RegionPicker alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64)];
    self.pickerView.pickerView.dataSource = self;
    self.pickerView.pickerView.delegate = self;
    [self.pickerView.confirmButton addTarget:self action:@selector(regionSelectAction) forControlEvents:UIControlEventTouchUpInside];
    [self.pickerView setHidden:YES];
    [self.view addSubview:self.pickerView];
    
    
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 10;
    }else if(section == 1){
        return self.dataCertificateModelArray.count;
    }else if(section == 2){
        return self.dataEducationModelArray.count;
    }else if(section == 3){
        return self.dataWorkExperienceModelArray.count;
    }else if(section == 4){
        return self.dataProjectExperienceModelArray.count;
    }else{
        return 1;
    }
}

- (void)textFieldDidChange: (UITextField *)sender {

    NSInteger indexTag = sender.tag;
    if (indexTag == 301) {
        _model.strDirection = sender.text;
        if (sender.text.length > 15) {
             sender.text = [sender.text substringToIndex:15];
        }
    }
    if (indexTag == 303) {
        _model.strAge = sender.text;
    }
    if (indexTag == 307) {
        _model.strExpectPrice = sender.text;
    }
    if (indexTag == 308) {
        _model.strMoblie = sender.text;
    }
    if (indexTag == 309) {
        _model.strEmail = sender.text;
    }
}
-(void)textViewDidChange:(UITextView *)textView {
    
    if (textView.tag == 400) {
        _model.strAssessment = textView.text;
        
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCell];
    if (!cell) {
        cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:strCell];
    }else{
        while ([cell.contentView.subviews lastObject]) {
            [[cell.contentView.subviews lastObject] removeFromSuperview];
        }
    }
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    
    //基本信息
    
    if (indexPath.section == 0) {
        
        NSArray *arrKinds = @[@"求职岗位",@"方        向",@"性        别",@"年        龄",@"学        历",@"工作年限",@"求职区域",@"期望薪资",@"联系电话",@"联系邮箱"];
        cell.textLabel.text = arrKinds[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:16];
        cell.textLabel.textColor = strColor(@"333");
        
        _textField = [[UITextField alloc] init];
        _textField.tag = indexPath.row + 300;
        _textField.textAlignment = NSTextAlignmentRight;
        _textField.font = [UIFont systemFontOfSize:15];
        [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        [cell.contentView addSubview:_textField];
        [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-20);
            make.left.equalTo(@100);
            make.top.bottom.equalTo(@0);
        }];
        
        // 添加箭头
        UIImageView *imageView = [UIImageView new];
        imageView.image = [UIImage imageNamed:@"icon_user_list_more"];
        [cell.contentView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@5);
            make.centerY.equalTo(cell.contentView);
        }];
        
        switch (indexPath.row) {
            case 0:
                _textField.text =  _model.strJobs;
                _textField.enabled = false;
                
                break;
            case 1:
                _textField.text = _model.strDirection;
                imageView.hidden = YES;
                break;
            case 2:
                _textField.text = _model.strSex;
                _textField.enabled = false;
                break;
            case 3:
                _textField.keyboardType = UIKeyboardTypeNumberPad;
                _textField.text = _model.strAge;
                imageView.hidden = YES;
                
                break;
            case 4:
                _textField.text = _model.strAcademic;
                _textField.enabled = false;
                break;
            case 5:
                _textField.text = _model.strExperience;
                _textField.enabled = false;
                break;
            case 6:
                _textField.text = _model.strJobAddress;
                _textField.enabled = false;
                break;
            case 7:
                _textField.text = _model.strExpectPrice;
                _textField.enabled = false;
                break;
            case 8:
                _textField.keyboardType = UIKeyboardTypeNumberPad;
                _textField.text = _model.strMoblie;
                imageView.hidden = YES;
                break;
            case 9:
                _textField.keyboardType = UIKeyboardTypeEmailAddress;
                _textField.text = _model.strEmail;
                imageView.hidden = YES;
                break;
                
            default:
                break;
        }
        
    }else if (indexPath.section == 1) {
        cell.textLabel.text = @"";
        CertificateModel *model = _dataCertificateModelArray[indexPath.row];
        [self setLayoutBase:cell.contentView title:model.strNameCertificate time:model.strCertificateProfessional msg:model.strCertificateGrade];
    }else if (indexPath.section == 2) {
        cell.textLabel.text = @"";
        EducationModel *model = _dataEducationModelArray[indexPath.row];
        [self setLayoutBase:cell.contentView title:model.strSchoolName time:model.strGraduationTime msg:model.strProfessionalName];
    }else if (indexPath.section == 3) {
        cell.textLabel.text = @"";
        WorkExperienceModel *model = _dataWorkExperienceModelArray[indexPath.row];
        [self setLayoutBase:cell.contentView title:model.strJobs time:[NSString stringWithFormat:@"%@-%@",model.strInduction,model.strDeparture] msg:model.strCompanyName];
    }else if (indexPath.section == 4) {
        cell.textLabel.text = @"";
        ProjectExperienceModel *model = _dataProjectExperienceModelArray[indexPath.row];
        [self setLayoutBase:cell.contentView title:model.strProjectName time:[NSString stringWithFormat:@"%@-%@",model.strStartTime,model.strEndTime] msg:@""];
    } else{//
        cell.textLabel.text = @"";
        _textAssessment = [SZTextView new];
        _textAssessment.tag = 400;
        _textAssessment.delegate = self;
        _textAssessment.text = _model.strAssessment;
        _textAssessment.placeholder = @"自我评价";
        _textAssessment.font = [UIFont systemFontOfSize:15];
        [cell.contentView addSubview:_textAssessment];
        [_textAssessment mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@10);
            make.top.equalTo(@15);
            make.right.equalTo(@-15);
            make.bottom.equalTo(@-15);
        }];
    }
    
    
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 50;
    }else if (indexPath.section == 4){
        return 60;
    }else if (indexPath.section == 5){
        return 150;
    }else{
        return 90;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 10.0f;
    }else{
        return 45;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01f;
    
}

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
    headerView.backgroundColor = strColor(@"f6f6f6");
    NSArray *arrMsg = @[@"",@"持有证书",@"教育经历",@"工作经验",@"项目经验",@"自我评价"];
    UILabel *labelMsg = [[UILabel alloc] initWithFrame:CGRectMake(0, 45/2-3, 100, 16)];
    labelMsg.font = [UIFont systemFontOfSize:16];
    labelMsg.text = arrMsg[section];
    [headerView addSubview:labelMsg];
    
    if (section!=0 &&section != 5) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"icon_resume_add"] forState:UIControlStateNormal];
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [button setTitleColor:strColor(@"ff7900") forState:UIControlStateNormal];
        [button setTitle:@"添加" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        button.tag = 800 + section;
        [button addTarget:self action:@selector(OnClick:) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:button];
        [headerView addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@-10);
            make.centerY.equalTo(headerView).offset(6);
            make.width.equalTo(@80);
        }];
    }
    
    return headerView;
}
#pragma mark -- 添加按钮 点击事件
-(void)OnClick:(UIButton *)sender{
    if (sender.tag == 801) {
        AddCertificateViewController *addCertificate = [AddCertificateViewController new];
        
        addCertificate.addCertificate = ^(NSString *strNameCertificate, NSString *strCertificateProfessional, NSString *strCertificateGrade) {
            
            CertificateModel *model = [[CertificateModel alloc]init];
            model.strNameCertificate = strNameCertificate;
            model.strCertificateProfessional = strCertificateProfessional;
            model.strCertificateGrade = strCertificateGrade;
            [self.dataCertificateModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:addCertificate animated:YES];
    }
    
    if (sender.tag == 802) {
        AddEducationViewController *addEducation = [AddEducationViewController new];
        addEducation.education = ^(NSString *strSchoolName, NSString *strProfessionalName, NSString *strRecord, NSString *strGraduationTime) {
            
            EducationModel *model = [[EducationModel alloc]init];
            model.strSchoolName = strSchoolName;
            model.strProfessionalName = strProfessionalName;
            model.strRecord = strRecord;
            model.strGraduationTime = strGraduationTime;
            [self.dataEducationModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:addEducation animated:YES];
    }
    
    if (sender.tag == 803) {
        AddWorkExperienceViewController *work = [[AddWorkExperienceViewController alloc] init];
        work.workExperience = ^(NSString *strJobs, NSString *strCompanyName, NSString *strInduction, NSString *strDeparture, NSString *strJobDescription) {
            
            WorkExperienceModel *model = [[WorkExperienceModel alloc]init];
            model.strJobs = strJobs;
            model.strCompanyName = strCompanyName;
            model.strInduction = strInduction;
            model.strDeparture = strDeparture;
            model.strJobDescription = strJobDescription;
            [self.dataWorkExperienceModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:work animated:YES];
    }
    
    if (sender.tag == 804) {
        AddProjectExperienceViewController *work = [[AddProjectExperienceViewController alloc] init];
        work.projectExperience = ^(NSString *strProjectName, NSString *strPosition, NSString *strStartTime, NSString *strEndTime, NSString *strProjectMsg) {
            
            ProjectExperienceModel *model = [[ProjectExperienceModel alloc]init];
            model.strProjectName = strProjectName;
            model.strPosition = strPosition;
            model.strStartTime = strStartTime;
            model.strEndTime = strEndTime;
            model.strProjectMsg = strProjectMsg;
            [self.dataProjectExperienceModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:work animated:YES];
    }
}

#pragma  mark - 每一段的点击事件

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
#pragma mark --***************************************基本信息
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            JobsChooseViewController *jobs = [JobsChooseViewController new];  //  岗位选择
            jobs.addResume = @"1";
            [self.navigationController pushViewController:jobs animated:YES];
        }
        // 性别
        if (indexPath.row == 2) {
            NSArray * educationArray = @[@"男",@"女"];
            zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:educationArray andHeadTitle:@"性别" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
                _model.strSex = choiceString;
                [self reloadInputViewsRow:indexPath.row andSection:indexPath.section];
                [pickerView dismissPicker];
            }];
            [pickerView show];
        }
        //学历
        if (indexPath.row == 4) {
            NSArray * educationArray = @[@"不限",@"初中",@"高中",@"中专",@"大专",@"本科",@"博士",@"硕士"];
            zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:educationArray andHeadTitle:@"学历" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
                _model.strAcademic = choiceString;
                [self reloadInputViewsRow:indexPath.row andSection:indexPath.section];
                [pickerView dismissPicker];
            }];
            [pickerView show];
        }
        // 工作年限
        if (indexPath.row == 5) {
            NSArray * educationArray = @[@"不限",@"应届生",@"1年以内",@"1-3年",@"3-5年",@"5-10年",@"10年以上"];
            zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:educationArray andHeadTitle:@"工作年限" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
                _model.strExperience = choiceString;
                [self reloadInputViewsRow:indexPath.row andSection:indexPath.section];
                [pickerView dismissPicker];
            }];
            [pickerView show];
        }
        // 求职区域
        if (indexPath.row == 6) {
            
            if(!self.province) {
                
                NSString *jsonPath = [[NSBundle mainBundle]pathForResource:@"region" ofType:@"json"];
                NSData *jsonData = [[NSData alloc]initWithContentsOfFile:jsonPath];
                self.province = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
                self.city = self.province[0][@"city"];
                self.country = self.city[0][@"country"];
                self.mem_province = self.province[0][@"province_code"];
                self.mem_city = self.city[0][@"city_code"];
                self.mem_country = self.country[0][@"country_code"];
                _model.strJobAddress = [NSString stringWithFormat:@"%@%@%@",self.province[0][@"province_name"], self.city[0][@"city_name"], self.country[0][@"country_name"]];
                [self.pickerView setHidden:NO];
                [self.pickerView.pickerView reloadAllComponents];
            }else {
                [self.pickerView setHidden:NO];
                [self.pickerView.pickerView reloadAllComponents];
            }
            
        }
        // 期望薪资
        if (indexPath.row == 7) {
            NSArray * educationArray = @[@"2k以下", @"2k-5k", @"5k-10k", @"10k-15k", @"15k-25k" ];
            zySheetPickerView * pickerView = [zySheetPickerView ZYSheetStringPickerWithTitle:educationArray andHeadTitle:@"期望薪资" Andcall:^(zySheetPickerView *pickerView, NSString *choiceString) {
                _model.strExpectPrice = choiceString;
                [self reloadInputViewsRow:indexPath.row andSection:indexPath.section];
                [pickerView dismissPicker];
            }];
            [pickerView show];
        }
    }
    
#pragma mark --***************************************持有证书
    if (indexPath.section == 1) {
        AddCertificateViewController *addCertificate = [AddCertificateViewController new];
        addCertificate.indexEdit = 1;// 编辑
        //传值
        CertificateModel *model = _dataCertificateModelArray[indexPath.row];
        addCertificate.editNameCertificate = model.strNameCertificate;
        addCertificate.editCertificateProfessional = model.strCertificateProfessional;
        addCertificate.editCertificateGrade = model.strCertificateGrade;
        
        addCertificate.addCertificate = ^(NSString *strNameCertificate, NSString *strCertificateProfessional, NSString *strCertificateGrade) {
            
            if (model.strNameCertificate != strNameCertificate ||
                model.strCertificateProfessional != strCertificateProfessional ||
                model.strCertificateGrade != strCertificateGrade) {
                [_dataCertificateModelArray removeObjectAtIndex:indexPath.row];
            }
            if ([strNameCertificate isEqualToString: @""]) {
                [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                return ;
            }
            
            CertificateModel *model = [[CertificateModel alloc]init];
            model.strNameCertificate = strNameCertificate;
            model.strCertificateProfessional = strCertificateProfessional;
            model.strCertificateGrade = strCertificateGrade;
            [self.dataCertificateModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:addCertificate animated:YES];
    }
    
#pragma mark --***************************************教育经验
    if (indexPath.section == 2) {
        AddEducationViewController *addEducation = [AddEducationViewController new];
        addEducation.indexEdit = 1;// 编辑
        //传值
        EducationModel *model = self.dataEducationModelArray[indexPath.row];
        addEducation.editSchoolName = model.strSchoolName;
        addEducation.editProfessionalName = model.strProfessionalName;
        addEducation.editRecord = model.strRecord;
        addEducation.editGraduationTime = model.strGraduationTime;
        
        addEducation.education = ^(NSString *strSchoolName, NSString *strProfessionalName, NSString *strRecord, NSString *strGraduationTime) {
            
            if (model.strSchoolName != strSchoolName ||
                model.strProfessionalName != strProfessionalName ||
                model.strRecord != strRecord  ||
                model.strGraduationTime != strGraduationTime) {
                [self.dataEducationModelArray removeObjectAtIndex:indexPath.row];
            }
            if ([strSchoolName isEqualToString: @""]) {
                [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                return ;
            }
            
            EducationModel *model = [[EducationModel alloc]init];
            model.strSchoolName = strSchoolName;
            model.strProfessionalName = strProfessionalName;
            model.strRecord = strRecord;
            model.strGraduationTime = strGraduationTime;
            [self.dataEducationModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:addEducation animated:YES];
    }
#pragma mark --***************************************工作经验
    if (indexPath.section == 3) {
        AddWorkExperienceViewController *work = [[AddWorkExperienceViewController alloc] init];
        work.indexEdit = 1;// 编辑
        //传值
        WorkExperienceModel *model = self.dataWorkExperienceModelArray[indexPath.row];
        work.editJobs = model.strJobs;
        work.editCompanyName = model.strCompanyName;
        work.editInduction = model.strInduction;
        work.editDeparture = model.strDeparture;
        work.editJobDescription = model.strJobDescription;
        
        work.workExperience = ^(NSString *strJobs, NSString *strCompanyName, NSString *strInduction, NSString *strDeparture, NSString *strJobDescription) {
            
            if (model.strJobs != strJobs ||
                model.strCompanyName != strCompanyName ||
                model.strInduction != strInduction  ||
                model.strDeparture != strDeparture||
                model.strJobDescription != strJobDescription) {
                [self.dataWorkExperienceModelArray removeObjectAtIndex:indexPath.row];
            }
            if ([strJobs isEqualToString: @""]) {
                [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                return ;
            }
            
            WorkExperienceModel *model = [[WorkExperienceModel alloc]init];
            model.strJobs = strJobs;
            model.strCompanyName = strCompanyName;
            model.strInduction = strInduction;
            model.strDeparture = strDeparture;
            model.strJobDescription = strJobDescription;
            [self.dataWorkExperienceModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:work animated:YES];
    }
    
#pragma mark --***************************************项目经验
    if (indexPath.section == 4) {
        AddProjectExperienceViewController *work = [[AddProjectExperienceViewController alloc] init];
        work.indexEdit = 1;// 编辑
        //传值
        ProjectExperienceModel *model = self.dataProjectExperienceModelArray[indexPath.row];
        work.editProjectName = model.strProjectName;
        work.editPosition = model.strPosition;
        work.editStartTime = model.strStartTime;
        work.editEndTime = model.strEndTime;
        work.editProjectMsg = model.strProjectMsg;
        
        work.projectExperience = ^(NSString *strProjectName, NSString *strPosition, NSString *strStartTime, NSString *strEndTime, NSString *strProjectMsg) {
            
            if (model.strProjectName != strProjectName ||
                model.strPosition != strPosition ||
                model.strStartTime != strStartTime  ||
                model.strEndTime != strEndTime||
                model.strProjectMsg != strProjectMsg) {
                [self.dataProjectExperienceModelArray removeObjectAtIndex:indexPath.row];
            }
            if ([strProjectName isEqualToString: @""]) {
                [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
                return ;
            }
            
            ProjectExperienceModel *model = [[ProjectExperienceModel alloc]init];
            model.strProjectName = strProjectName;
            model.strPosition = strPosition;
            model.strStartTime = strStartTime ;
            model.strEndTime = strEndTime;
            model.strProjectMsg = strProjectMsg;
            [self.dataProjectExperienceModelArray addObject:model];
            [self.tableView reloadData];
            
        };
        [self.navigationController pushViewController:work animated:YES];
    }
    
}

#pragma mark -- 指定刷新行段
-(void)reloadInputViewsRow:(NSInteger)row andSection:(NSInteger)section{
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:row inSection:section];
    [_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}



#pragma mark -- 持有证书、教育经历、工作经验
-(void)setLayoutBase:(UIView*)view title:(NSString *)title time:(NSString*)time msg:(NSString*)msg{
    
    UIView *viewbg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, 10)];
    viewbg.backgroundColor = strColor(@"f6f6f6");
    [view addSubview:viewbg];
    
    //标题
    UILabel *labelTitle = [[UILabel alloc] init];
    [self setLabel:labelTitle addName:title andFont:15 and:strColor(@"333") andCenter:2 andView:view];
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.top.equalTo(@27);
        make.right.equalTo(@-100);
        make.height.equalTo(@18);
    }];
    
    //类别/时间
    UILabel *labelTime = [UILabel new];
    [self setLabel:labelTime addName:time andFont:14 and:strColor(@"999") andCenter:3 andView:view];
    [labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-15);
        make.top.equalTo(@27);
        make.width.equalTo(@200);
        make.height.equalTo(@18);
    }];
    
    // 描述
    UILabel *labelMsg = [UILabel new];
    [self setLabel:labelMsg addName:msg andFont:14 and:strColor(@"999") andCenter:2 andView:view];
    [labelMsg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@15);
        make.bottom.equalTo(@-17);
        make.right.equalTo(@-15);
        make.height.equalTo(@18);
    }];
}



-(void)setLabel:(UILabel *)lableName addName:(NSString *)name andFont:(CGFloat)size and:(UIColor *)color andCenter:(int)intCenter andView:(id)views{
    ![name isKindOfClass:[NSNull class]] ? lableName.text = name : nil;
    lableName.font = [UIFont systemFontOfSize:size];
    lableName.textColor = color;
    switch (intCenter) {
        case 1:
            lableName.textAlignment = NSTextAlignmentCenter;
            break;
        case 2:
            lableName.textAlignment = NSTextAlignmentLeft;
            break;
        case 3:
            lableName.textAlignment = NSTextAlignmentRight;
            break;
        default:
            break;
    }
    [views addSubview:lableName];
}


// 区域选择确定
- (void)regionSelectAction {
    [self.pickerView setHidden:YES];
    if (self.selectedRegion.length==0) {
        _model.strJobAddress = @"北京北京市东城区";
    }else{
        _model.strJobAddress = self.selectedRegion;
    }
    self.province_code = self.mem_province;
    self.city_code = self.mem_city;
    self.country_code = self.mem_country;
    [self.tableView reloadData];
}

#pragma mark - UIPickerView datasource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    switch (component) {
        case 0:
        {
            if(![self.province isKindOfClass:[NSNull class]]) {
                return self.province.count;
            }else {
                return 0;
            }
        }
            break;
        case 1:
        {
            if(![self.city isKindOfClass:[NSNull class]]) {
                return self.city.count;
            }else {
                return 0;
            }
        }
            break;
        case 2:
        {
            if(![self.country isKindOfClass:[NSNull class]]) {
                return self.country.count;
            }else {
                return 0;
            }
        }
            break;
        default:
            break;
    }
    return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    switch (component) {
            
        case 0:
        {
            // 省份
            return self.province[row][@"simple_province_name"];
        }
            break;
        case 1:
        {
            // 城市
            return self.city[row][@"simple_city_name"];
        }
            break;
        case 2:
        {
            // 乡镇、街道
            return self.country[row][@"simple_country_name"];
        }
            break;
        default:
            break;
    }
    return nil;
}

#pragma mark - UIPickerView delegate
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    switch (component) {
        case 0:
        {
            // 省份
            self.city = self.province[row][@"city"];
            self.country = self.city[0][@"country"];
            [pickerView selectRow:0 inComponent:1 animated:NO];
            [self pickerView:self.pickerView.pickerView didSelectRow:0 inComponent:1];
        }
            break;
        case 1:
        {
            // 城市
            self.country = self.city[row][@"country"];
            [pickerView selectRow:0 inComponent:2 animated:NO];
            [self pickerView:self.pickerView.pickerView didSelectRow:0 inComponent:2];
        }
            break;
        case 2:
        {
            // 乡镇、街道
        }
            break;
        default:
            break;
    }
    
    
    self.mem_province = self.province[[pickerView selectedRowInComponent:0]][@"province_code"];
    self.selectedRegion = self.province[[pickerView selectedRowInComponent:0]][@"province_name"];
    
    self.mem_city = self.city[[pickerView selectedRowInComponent:1]][@"city_code"];
    self.selectedRegion = [self.selectedRegion stringByAppendingString:self.city[[pickerView selectedRowInComponent:1]][@"city_name"]];
    
    if([self.country isKindOfClass:[NSArray class]]) {
        self.mem_country = self.country[[pickerView selectedRowInComponent:2]][@"country_code"];
        self.selectedRegion = [self.selectedRegion stringByAppendingString:self.country[[pickerView selectedRowInComponent:2]][@"country_name"]];
    }else {
        self.mem_country = @"1";
    }
    
    [pickerView reloadAllComponents];
}


#pragma mark - 上传数据
-(void)upPostData{
    
    // 基本信息
    
    if (_model.strJobs.length==0) {
        SHuiMBhudTextTimeStr(@"请选择求职岗位");
        return;
    }
    
    if (_model.strDirection.length==0) {
        _model.strDirection = @"";
     }
    
    if (_model.strSex.length==0) {
        SHuiMBhudTextTimeStr(@"请选择性别");
        return;
    }
    
    if (_model.strAge.length==0) {
        SHuiMBhudTextTimeStr(@"请填写年龄");
        return;
    }
    
    if (_model.strAcademic.length==0) {
        SHuiMBhudTextTimeStr(@"请选择学历");
        return;
    }
    
    if (_model.strExperience.length==0) {
        SHuiMBhudTextTimeStr(@"请选择工作年限");
        return;
    }
    if (_model.strJobAddress.length==0) {
        SHuiMBhudTextTimeStr(@"求职区域");
        return;
    }
    if (_model.strExpectPrice.length==0) {
        SHuiMBhudTextTimeStr(@"请选择期望薪资");
        return;
    }
    if (_model.strMoblie.length==0) {
        SHuiMBhudTextTimeStr(@"请填写联系电话");
        return;
    }
    if (_model.strEmail.length==0) {
        SHuiMBhudTextTimeStr(@"请填写联系邮箱");
        return;
    }
    if (_model.strAssessment.length==0) {
        SHuiMBhudTextTimeStr(@"请填写自我评价");
        return;
    }
    
    // 添加(可不传)
    //证书
    if (_dataCertificateModelArray.count==0) {
        _strJsonCertificate = @"";
    }else{
        NSMutableArray *arrList = @[].mutableCopy;
        for (int i = 0; i <_dataCertificateModelArray.count; i ++) {
            CertificateModel *model = self.dataCertificateModelArray[i];
            NSDictionary *dic = @{@"name":model.strNameCertificate,
                                  @"level":model.strCertificateProfessional,
                                  @"major":model.strCertificateGrade};
            [arrList addObject:[self ObjectTojsonString:dic]];
        }
        _strJsonCertificate =[NSString stringWithFormat:@"[%@]",[arrList componentsJoinedByString:@","]];
        
    }
    //教育经历
    if (_dataEducationModelArray.count==0) {
        _strJsonEducation = @"";
    }else{
        NSMutableArray *arrList = @[].mutableCopy;
        for (int i = 0; i <_dataEducationModelArray.count; i ++) {
            EducationModel *model = self.dataEducationModelArray[i];
            NSDictionary *dic = @{@"school_name":model.strSchoolName,
                                  @"graduate_year":model.strGraduationTime,
                                  @"profession":model.strProfessionalName,
                                  @"education":model.strRecord};
            [arrList addObject:[self ObjectTojsonString:dic]];
        }
        _strJsonEducation =[NSString stringWithFormat:@"[%@]",[arrList componentsJoinedByString:@","]];
    }
    //工作经验
    if (_dataWorkExperienceModelArray.count==0) {
        _strJsonWorkExperience = @"";
    }else{
        NSMutableArray *arrList = @[].mutableCopy;
        for (int i = 0; i <_dataWorkExperienceModelArray.count; i ++) {
            WorkExperienceModel *model = self.dataWorkExperienceModelArray[i];
            NSDictionary *dic = @{@"company_name":model.strJobs,
                                  @"position":model.strCompanyName,
                                  @"in_date":model.strInduction,
                                  @"out_date":model.strDeparture,
                                  @"work_content":model.strJobDescription};
            [arrList addObject:[self ObjectTojsonString:dic]];
        }
        _strJsonWorkExperience =[NSString stringWithFormat:@"[%@]",[arrList componentsJoinedByString:@","]];
    }
    //项目经验
    if (_dataProjectExperienceModelArray.count==0) {
        _strJsonProjectExperience = @"";
    }else{
        NSMutableArray *arrList = @[].mutableCopy;
        for (int i = 0; i <_dataProjectExperienceModelArray.count; i ++) {
            ProjectExperienceModel *model =_dataProjectExperienceModelArray[i];
            NSDictionary *dic = @{@"project_name":model.strProjectName,
                                  @"duty":model.strPosition,
                                  @"b_time":model.strStartTime,
                                  @"e_time":model.strEndTime,
                                  @"project_describe":model.strProjectMsg};
            [arrList addObject:[self ObjectTojsonString:dic]];
        }
        _strJsonProjectExperience =[NSString stringWithFormat:@"[%@]",[arrList componentsJoinedByString:@","]];
    }
    
    
    isUser
    NSString *strUrl;
    NSDictionary *parameter;
    if (_strResumeId) {
        strUrl = [NSString stringWithFormat:post_editResume_api];
        parameter = @{@"user_id":user.user_id,
                      @"token":user.token,
                      @"cate_id":_model.strCateId,
                      @"resume_id":_strResumeId,
                      @"sex":_model.strSex,
                      @"age":_model.strAge,
                      @"education":_model.strAcademic,
                      @"work_year":_model.strExperience,
                      @"province":_province_code,
                      @"city":_city_code,
                      @"county":_country_code,
                      @"salary":_model.strExpectPrice,
                      @"phone":_model.strMoblie,
                      @"email":_model.strEmail,
                      @"resume_brief":_model.strAssessment,
                      @"direction":_model.strDirection,
                      @"certificate":_strJsonCertificate,
                      @"project_experience":_strJsonProjectExperience,
                      @"work_experience":_strJsonWorkExperience,
                      @"edu_experience":_strJsonEducation};
    }else{
        strUrl = [NSString stringWithFormat:post_addNewResume_api];
        parameter = @{@"user_id":user.user_id,
                      @"token":user.token,
                      @"cate_id":_model.strCateId,
                      @"sex":_model.strSex,
                      @"age":_model.strAge,
                      @"education":_model.strAcademic,
                      @"work_year":_model.strExperience,
                      @"province":_province_code,
                      @"city":_city_code,
                      @"county":_country_code,
                      @"salary":_model.strExpectPrice,
                      @"phone":_model.strMoblie,
                      @"email":_model.strEmail,
                      @"resume_brief":_model.strAssessment,
                      @"direction":_model.strDirection,
                      @"certificate":_strJsonCertificate,
                      @"project_experience":_strJsonProjectExperience,
                      @"work_experience":_strJsonWorkExperience,
                      @"edu_experience":_strJsonEducation};
    }
    
    
    [MBProgressHUD showMessag:@"保存中..." withDelay:0 toView:self. view withMode:MBProgressHUDModeIndeterminate hideWithDelay:0];
    [PostNetWorking postNetWorkingStr:strUrl andparameters:parameter Success:^(id responseObject) {
        NSLog(@"返回数据---%@",responseObject);
        
        if ([responseObject[@"code"] intValue] == 200) {
            
            SHuiMBHidleYes
            SHuiMBhudTextTimeStr(@"保存成功");
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                
                [self.navigationController popViewControllerAnimated:YES];
                
            });
            
            
        }else{
            SHuiMBHidleYes
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
        
    } failed:^(NSError *error) {
        SHuiMBHidleYes
        SHuiMBhudTextTimeStr(@"网络错误");
    }];
    
    
}


-(NSString*)ObjectTojsonString:(id)object
{
    NSString *jsonString = [[NSString alloc]init];
    NSError *error;
    NSData *jsonData = [NSJSONSerialization  dataWithJSONObject:object  options:NSJSONWritingPrettyPrinted  error:&error];
    if (! jsonData) {
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    NSRange range = {0,jsonString.length};
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    NSRange range2 = {0,mutStr.length};
    [mutStr replaceOccurrencesOfString:@"\n"  withString:@"" options:NSLiteralSearch range:range2];
    NSRange range3 = {0, mutStr.length};
    NSString * str = @"\\";
    [mutStr replaceOccurrencesOfString:str withString:@"" options:NSLiteralSearch range:range3];
    return mutStr;
}


#pragma mark -- 获得数据添加到列表上

-(void)getListDatas{
    
    isUser
    NSString *strUrl = [NSString stringWithFormat:post_getEditResume_api];
    NSDictionary *dicParameter = @{@"user_id":user.user_id,
                                   @"token":user.token,
                                   @"resume_id":_strResumeId};
    
    [PostNetWorking postNetWorkingStr:strUrl andparameters:dicParameter Success:^(id responseObject) {
        
        if ([responseObject[@"code"] intValue] == 200) {
            
            //基本信息
            
            _model.strJobs = responseObject[@"datas"][@"cate_name"];
            _model.strCateId = responseObject[@"datas"][@"cate_id"];
            _model.strDirection = responseObject[@"datas"][@"direction"];
            _model.strSex = responseObject[@"datas"][@"sex"];
            _model.strAge = responseObject[@"datas"][@"age"];
            _model.strAcademic = responseObject[@"datas"][@"education"];
            _model.strExperience = responseObject[@"datas"][@"work_year"];
            _model.strJobAddress = [NSString stringWithFormat:@"%@%@%@",responseObject[@"datas"][@"province_name"],responseObject[@"datas"][@"city_name"],responseObject[@"datas"][@"county_name"]];
            _country_code = responseObject[@"datas"][@"county"];
            _city_code = responseObject[@"datas"][@"city"];
            _province_code = responseObject[@"datas"][@"province"];
            _model.strExpectPrice = responseObject[@"datas"][@"salary"];
            _model.strMoblie = responseObject[@"datas"][@"phone"];
            _model.strEmail = responseObject[@"datas"][@"email"];
            _model.strAssessment = responseObject[@"datas"][@"resume_brief"];
            
            //证书
            for (NSDictionary *dicCer in responseObject[@"datas"][@"certificate"]) {
                CertificateModel *model = [[CertificateModel alloc] init];
                model.strNameCertificate = dicCer[@"name"];
                model.strCertificateProfessional = dicCer[@"major"];
                 model.strCertificateGrade = dicCer[@"level"];
                [_dataCertificateModelArray addObject:model];
            }
            //教育
            for (NSDictionary *dicEdu in responseObject[@"datas"][@"education_experience"]) {
                EducationModel *model = [[EducationModel alloc] init];
                model.strSchoolName = dicEdu[@"school_name"];
                model.strProfessionalName = dicEdu[@"profession"];
                model.strRecord = dicEdu[@"education"];
                model.strGraduationTime = dicEdu[@"graduate_year"];
                [_dataEducationModelArray addObject:model];
            }
            //工作
            for (NSDictionary *dicWork in responseObject[@"datas"][@"work_experience"]) {
                WorkExperienceModel *model = [[WorkExperienceModel alloc] init];
                model.strJobs = dicWork[@"position"];
                model.strCompanyName = dicWork[@"company_name"];
                model.strInduction = dicWork[@"in_date"];
                model.strDeparture = dicWork[@"out_date"];
                model.strJobDescription = dicWork[@"work_content"];
                [_dataWorkExperienceModelArray addObject:model];
            }
            //项目
            for (NSDictionary *dicWork in responseObject[@"datas"][@"project_experience"]) {
                ProjectExperienceModel *model = [[ProjectExperienceModel alloc] init];
                model.strProjectName = dicWork[@"project_name"];
                model.strPosition = dicWork[@"duty"];
                model.strStartTime = dicWork[@"b_time"];
                model.strEndTime = dicWork[@"e_time"];
                model.strProjectMsg = dicWork[@"project_describe"];
                [_dataProjectExperienceModelArray addObject:model];
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [self.tableView reloadData];
                
            });
        }else{
            SHuiMBhudTextTimeStr(responseObject[@"mark"]);
        }
        
        
    } failed:^(NSError *error) {
        
        SHuiMBhudTextTimeStr(@"网络错误");
    }];
    
}





@end
